package com.weh.booksystem.controller;

import com.weh.booksystem.service.AdministratorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author weh
 * @create 2023-06-26
 */
@RestController
@RequestMapping(value = "/administrators")
public class AdministratorController {

    private Logger log = LoggerFactory.getLogger(getClass());

    @Resource
    private AdministratorService administratorService;

    @PostMapping(value = "/login")
    public boolean AdminLogin(@RequestParam String name, @RequestParam String password, HttpServletRequest httpRequest){
        int administratorId = administratorService.getAdministratorId(name, password);
        HttpSession session = httpRequest.getSession();
        session.setAttribute("administratorId",administratorId);
        System.out.println("administratorId = " + administratorId);
        return (administratorService.getAdministrator(name, password) != null);
    }
}
